package cn.edu.ctbu.firstdata.restcontroller;

import cn.edu.ctbu.firstdata.domain.Student;
import cn.edu.ctbu.firstdata.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/webapi/student")
public class StudentRestController {

    @Autowired
    StudentService studentService;

    /**
     * 获取所有学生的信息，为ajaxlist.html设计
     * @return
     */
    @GetMapping("list")
    public List<Student> GetAll(){
        return  studentService.getAll();
    }

    /**
     * 根据姓名查询学生信息，为ajaxlist.html设计
     * @param name
     * @return
     */
    @GetMapping(value = "getbyname")
    public List<Student> findByName(String name) {
        return studentService.findByName(name);
    }


//    /**
//     * 示例：http://localhost:8080/webapi/student/4
//     * 其中4表示id
//     * @param id
//     * @return
//     */
//    @GetMapping(value = "{id}")
//    public Student GetById(@PathVariable Integer id){
//        return studentService.findById(id);
//    }
//
//    @DeleteMapping (value = "delete/{id}")
//    public boolean DeleteById(@PathVariable Integer id){
//        studentService.delete(id);
//        return true;
//    }
//
//    @PostMapping(value = "update")
//    public Integer Update(@RequestBody Student student){
//        studentService.save(student);
//        return student.getId();
//    }
}
